package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ghost.GhostModule;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GHOST_GET_DISPERSE_REWARD_FROM_CROSS, desc = "领取送财奖励跨服返回")
public class GhostGetDisperseRewardFromCrossCmd extends AbstractCommand {

    String randomReward = "";
    boolean notice = false;
    boolean isSpec = false;
    int type;
    long userResetTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GhostActivityProto.CrossGetDisperseGoldRewardRespMsg reqMsg = GhostActivityProto.CrossGetDisperseGoldRewardRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        userResetTime = reqMsg.getUserResetTime();
        if (ret == 0) {
            randomReward = reqMsg.getRandomReward();
            notice = reqMsg.getIsNotice();
            isSpec = reqMsg.getIsSpec();
            type = reqMsg.getType();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (ret != 0) {
            return;
        }

        GhostMgr.checkUserData(player);
        ret = player.getModule(GhostModule.class).getDisperseRewardFromCross(randomReward, notice, isSpec, type, userResetTime);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GhostActivityProto.GetDisperseGoldRewardRespMsg.Builder builder = GhostActivityProto.GetDisperseGoldRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GHOST_GET_DISPERSE_REWARD, builder);
        }
    }
}
